<script type="text/javascript">
function validate_form() {
    var name = $('#name').val();
    if((name.length < 1) || (name.length > 200)) {
    	$('#errorName').html('Tên danh mục từ 1-200 kí tự');
        return false;
    }
    else {
        return true;
    }
}
</script>
    <div class="list_category">
        <ul>
            <li><a href="<?php echo $this->baseUrl('admincp/furniturecategory'); ?>">Quản lý danh mục</a></li>
            <li><a href="<?php echo $this->baseUrl('admincp/furniturecategory/create'); ?>">Thêm danh mục mới</a></li>
        </ul>
    </div>
</div>

<!-- Begin Content -->
<div class="section">
    <div class="heading_section">
        <span>Sửa thông tin danh mục</span>
    </div>
    
    <div class="content">
    <form action="" method="post" onsubmit="return validate_form()">
        <table class="table">
            <tr>
                <td class="td1"><?php echo $this->formLabel('parents','Danh mục cha'); ?>&nbsp;&nbsp;&nbsp;</td>
                <td class="td2">
                    <select name="parents" id="parents" class="selectbox">
						<?php
                            foreach($this->data as $value) :
    							$levelCss = '';
    				            if($value['level'] == 0){
    				            	$name = $value['name'];
    				            }else if($value['level'] == 1){
    				            	$name = ' + ' . $value['name'];
    				            }else{
    				            	$name = ' - - ' . $value['name'];
    				            	$levelCss =  'padding-left: ' . (10 * $value['level']) . 'px;';
    				            }
                                if($value['level'] < 2) :
                                    if($value['id'] == $this->data2['parents']) :
                        ?>
            						<option selected="selected" value="<?php echo $value['id']; ?>" style="<?php echo $levelCss; ?>"><?php echo $name; ?></option>
                                <?php
                                    else :
                                        if($value['id'] == $this->data2['id']) :
                                ?>
                                        <option disabled="disabled" value="<?php echo $value['id']; ?>" style="<?php echo $levelCss; ?>"><?php echo $name; ?></option>
                                        <?php else : ?>
                                        <option value="<?php echo $value['id']; ?>" style="<?php echo $levelCss; ?>"><?php echo $name; ?></option>
                        <?php
                                        endif;
                                    endif;
                                endif;
                            endforeach;
                        ?>
					</select>
                </td>
                <td class="td3">&nbsp;</td>
            </tr>
            <tr>
                <td class="td1"><?php echo $this->formLabel('name','Tên danh mục'); ?>&nbsp;<span class="error-msg">*</span></td>
                <td class="td2"><?php echo $this->formText('name',$this->data2['name'],array('class'=>'input')); ?></td>
                <td class="td3" id="errorName"><?php echo $this->errorName; ?></td>
            </tr>
            <tr>
                <td class="td1">&nbsp;</td>
                <td class="td2">
                    <?php echo $this->formSubmit('submit','Cập nhật',array('class'=>'button')); ?>
                    <?php echo $this->formReset('reset','Nhập lại',array('class'=>'button')); ?>
                </td>
                <td class="td3">&nbsp;</td>
            </tr>
        </table>
    </form>
    </div>
</div>
<!-- End Content -->